<?php

##################################################
#
# Copyright (c) 2004-2006 OIC Group, Inc.
# Written and Designed by James Hunt
#
# This file is part of Exponent
#
# Exponent is free software; you can redistribute
# it and/or modify it under the terms of the GNU
# General Public License as published by the Free
# Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# GPL: http://www.gnu.org/licenses/gpl.txt
#
##################################################
/**
* Change logs
* Jan 30, 2011 - trungdt - add password meter
* OCt 8, 2011 - trungdt - Fix bug password meter
*/
if (!defined('EXPONENT')) exit('');

/**
 * Password Control
 *
 * @author James Hunt
 * @copyright 2004-2006 OIC Group, Inc.
 * @version 0.95
 *
 * @package Subsystems
 * @subpackage Forms
 */

/**
* Change logs
* - Dec 14, 2011 - trungdt - Add required property
* 
 * Manually include the class file for formcontrol, for PHP4
 * (This does not adversely affect PHP5)
 */
require_once(BASE."subsystems/forms/controls/formcontrol.php");

/**
 * Password Control
 *
 * @package Subsystems
 * @subpackage Forms
 */
class passwordcontrol extends formcontrol {
	var $default = "";
	var $size = 0;
	var $maxlength = "";
	
	function name() { return "Password Field"; }
	
	/**
	* 
	* @param mixed $default
	* @param mixed $size
	* @param mixed $disabled
	* @param mixed $maxlength
	* @param mixed $first_field
	* @return passwordcontrol
	*/
	function passwordcontrol($default = "", $size = 0, $disabled = false, $maxlength = 30, $first_field="", $use_meter=true, $required=true) {
		// jan 30, 2011 - trungdt - add second field, to know that this is second password field or not
		$this->default = $default;
		$this->size = $size;
		$this->disabled = $disabled;
		$this->maxlength = $maxlength;
		// when we set this first field, we mean thris field must be the same password with first field
		$this->first_field=$first_field;
		// Oct 9, 2011 -trungdt - Add use meter
		$this->use_meter=$use_meter;
		// add required
		if ($required)
			$this->required= "required";
		else
			$this->required="";
	}
	
	function controlToHTML($name) {
        $lang = exponent_lang_loadFile('subsystems/form/control/passwordcontrol.php');
         
		$html = "<input class='password {$this->required}' type=\"password\" name=\"$name\" value=\"" . $this->default . "\" ";
		$html .= ($this->size?"size=\"".$this->size."\" ":"");
		$html .= ($this->disabled?"disabled ":"");
		$html .= ($this->maxlength?"maxlength=\"".$this->maxlength."\" ":"");
		$html .= ($this->tabindex >= 0?"tabindex=\"".$this->tabindex."\" ":"");
		$html .= ($this->accesskey != ""?"accesskey=\"".$this->accesskey."\" ":"");
		$html .= "/>";
		// jan 30, 2011 - trungdt - check same password
		if ($this->use_meter){
		if ($this->first_field != '')
		{
			$html.="<div id='{$name}_check' style='color: red; display: none;'>".$lang['re_pass_inco']."</div>";
			$html.="
				<script language='javascript'>
					jQuery('input[type=password]').keyup(function (){
							jQuery('#{$name}_check').hide();
							if (jQuery('[name={$name}]').val() == jQuery('[name={$this->first_field}]').val())
							{
								jQuery('#{$name}_check').hide();
							}
							else
							{
								jQuery('#{$name}_check').show();
							}
					});
				</script>
			";
		}
		else{
			$html.="
				<script language='javascript'>
					jQuery(document).ready(function(){
						jQuery('input[name={$name}]').pstrength();
					});
				</script>";
		}
		}
		return $html;
	}
	
	/**
	* Jan 30, 2011 - trungdt - Add this js
	*/
	function onRegister(&$form) {
        
		$form->addScript("js-password-metter", PATH_RELATIVE."js/jquery.pstrength-min_".LANG.".1.2.js");
	}
	
	function form($object) {

	}
	
	function update($values, $object) {

	}
	
	
	
	
}

?>
